import React from 'react';
import { Routes, Route } from 'react-router-dom';
import HomePage from '../pages/HomePage/HomePage';
import UserProfile from '../pages/UserProfile/UserProfile';
import ProductList from '../pages/ProductList/ProductList';
import NotFound from '../pages/NotFound/NotFound';
import TeamList from '../pages/TeamList/TeamList';
import TeamDetail from '../pages/TeamDetail/TeamDetail';
import PlayerList from '../pages/PlayerList/PlayerList';
import PlayerDetail from '../pages/PlayerDetail/PlayerDetail';

// 路由配置
const routes = [
  {
    path: '/',
    element: <HomePage />,
    title: '首页',
  },
  {
    path: '/homePage',
    element: <HomePage />,
    title: '首页',
  },
  {
    path: '/userProfile',
    element: <UserProfile />,
    title: '个人中心',
  },
  {
    path: '/productList',
    element: <ProductList />,
    title: '商品列表',
  },
  {
    path: '/teamList',
    element: <TeamList />,
    title: '球队列表',
  },
  {
    path: '/teamDetail',
    element: <TeamDetail />,
    title: '球队详情',
  },
  {
    path: '/teamDetail/:id',
    element: <TeamDetail />,
    title: '球队详情',
  },
  {
    path: '/playerList',
    element: <PlayerList />,
    title: '球员列表',
  },
  {
    path: '/playerDetail',
    element: <PlayerDetail />,
    title: '球员详情',
  },
  {
    path: '/playerDetail/:id',
    element: <PlayerDetail />,
    title: '球员详情',
  },
  {
    path: '*',
    element: <NotFound />,
    title: '页面未找到',
  },
];

// 路由组件
const AppRouter = () => {
  return (
    <Routes>
      {routes.map((route) => (
        <Route
          key={route.path}
          path={route.path}
          element={route.element}
        />
      ))}
    </Routes>
  );
};

// 根据路径获取页面标题
export const getPageTitle = (pathname) => {
  const route = routes.find(route => route.path === pathname);
  return route ? route.title : '应用';
};

// 根据路径获取当前页面标识
export const getCurrentPage = (pathname) => {
  switch (pathname) {
    case '/':
    case '/homePage':
      return 'homePage';
    case '/userProfile':
      return 'userProfile';
    case '/productList':
      return 'productList';
    default:
      return 'homePage';
  }
};

export default AppRouter;
